package com.easyhouse.websocket.service;

import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Service
public class WebSocketService {

    public static void  setJsonString(String userId, String msg) {
        //连接池的属性最大连接,最小空闲,最大空闲等
        JedisPoolConfig config=new JedisPoolConfig();
        config.setMaxIdle(5);
        config.setMinIdle(2);
        config.setMaxTotal(20);
        //创建一个连接6379端口的连接对象的连接池
        JedisPool pool=new JedisPool(config,"42.192.23.95",9000);
        //从池子中获取资源,jedis
        Jedis jedis = pool.getResource();
        jedis.set(userId,msg);
        System.out.println("数据已经存到redis中了");
        jedis.expire(userId,60*60*24*7);
        jedis.close();
    }



    public String getJsonString(String userId) {
        JedisPoolConfig config=new JedisPoolConfig();
        //创建一个连接6379端口的连接对象的连接池
        JedisPool pool=new JedisPool(config,"10.42.55.42",6380);
        //从池子中获取资源,jedis
        Jedis jedis = pool.getResource();
        String msg=jedis.get(userId);
        jedis.close();
        return msg;

    }






}
